﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SchoolManagementSystem.Controls;
using CoreData;
using Helper;
namespace SchoolManagementSystem.DetailsManager
{
    public partial class GroupUC : DetailUC
    {
        public GroupUC()
        {
            InitializeComponent();
            this.ObjectName = "nhóm người dùng";
            this.Code = "Group";
            this.Type = new Group();
            masterMainUC1.Model = RegisterService.RegisterServices.Group_Module_RoleService;
            masterMainUC1.DetailUCControl = new GrandPermissionGroupUC();
        }



        String GroupID = "1=1";
        protected override long DetailDisplay()
        {
            Group group = new Group();
            if(ID>0)
            {
                group = (Group)RegisterService.RegisterServices.GroupService.GetByID(ID);
                GroupID = ID.ToString(); //group.GroupGuidID;
            }
            txtcode.Text = group.Code;
            txtname.Text = group.Name;
            txtdescription.Text = group.Description;
            ckactive.Checked = group.Active;
            masterMainUC1.SearchString = " GroupID='" + GroupID + "'"; //get danh sach phan quyen
            masterMainUC1.DetailUCControl.SearchString = " GroupID='" + GroupID + "'";
            return ID;
            
        }

        protected override long Save()
        {
            Group group = new Group();
            if (ID > 0)
            {
                group = (Group)RegisterService.RegisterServices.GroupService.GetByID(ID);
            }
            group.Code = txtcode.Text;
            group.Name = txtname.Text;
            group.Description = txtdescription.Text;
            group.Active = ckactive.Checked;
            ID = RegisterService.RegisterServices.GroupService.Save(group);
            masterMainUC1.DetailUCControl.SearchString = ID.ToString() ; //((Group)RegisterService.RegisterServices.GroupService.GetByID(ID)).GroupGuidID;
            return ID;
        }


        public override bool Delete(long SelectedID)
        {

            return RegisterService.RegisterServices.GroupService.Delete((Group)RegisterService.RegisterServices.GroupService.GetByID(SelectedID));

        }

     
      
        private void GroupUC_Load(object sender, EventArgs e)
        {
            AddTextChanged(xtraTabPage1.Controls);
            AddTextChanged(xtraTabPage2.Controls);
        }

       

    }
}
